﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.FreeEntryHandler
{
    public class GetProjectOverheadList
    {
        public readonly ProjectOverheadRepository _projectOverheadRepository;

        public GetProjectOverheadList()
        {
            _projectOverheadRepository = new ProjectOverheadRepository();
        }

        public GetProjectOverheadList(ProjectOverheadRepository projectOverheadRepository)
        {
            _projectOverheadRepository = projectOverheadRepository;
        }

        public IEnumerable<ProjectOverheadModel> Execute()
        {
            try
            {
                IEnumerable<project_overheads> overheads = null;

                //get
                try
                {
                    overheads = _projectOverheadRepository.GetProjectOverheads();
                }
                catch (Exception exception)
                {
                    LogService.Service.Debug(exception);
                }
                if (overheads != null && overheads.Count() > 0)
                {
                    var result = from o in overheads
                                 select new ProjectOverheadModel(o);
                    return result;
                }
                return null;

            }
            catch (Exception ex)
            {
                LogService.Service.Error(ex);
                return null;
                throw;
            }

        }

    }
}
